



/*  metrowerks sample code  */



/*
	Note:  This main file requires the "hostIO" MSL Library that includes
	stdio file i/o support through the debugger host/target interface.  
	This is required as the regular MSL does not support file i/o 
	in order to save on memory requirements.
	
	If you open a file for binary, the debugger will treat it as raw data 
	when transfering between target and	host. 
	
	If you create a file for text, the debugger will perform a 16-bit to	
	8-bit character translation in order to make it easy to open the file
	on the host as text.
	
	
	host i/o requires a large heap (see related LCF)

*/


#include <stdio.h>
#include <stdlib.h>


static char filename[] = "fprintf.txt";  


int main(void)
{
	
  FILE *f;
  
  int fileResult = 0;
  int someFileHandle = 0;
  int rwCount = 0;
  
  int a = 56;
  char c = 'M';
  double x = 483.582;

  printf("open mode: w\n");
  printf("since no path, will be created in proj output dir\n\n");
  printf("open new or existing text file for writing\n");
  printf("and truncate\n");

  printf("fopen parameter 1: %s\n", filename);
  printf("fopen parameter 2: w\n");

  f = fopen(filename, "w");
  someFileHandle = f->handle;
  printf("file handle: %d\n\n",someFileHandle);
  
  printf("write formatted string to file\n");
  rwCount = fprintf(f, "%10s %4.4f %-10d\n%10c\n", filename, x, a, c);
  printf("fprintf return: %d \n", rwCount);
  
  printf("look at file on host to verify output\n");
  
  fileResult = fclose(f);
  printf("fclose result: %d \n\n", fileResult);

  printf("end fprint test\n\n");
  
  return(0);
}

